#include "../../src/common/JsonUtil.h"
#include "../../src/server/RpcRouter.h"
#include "../../src/server/RpcServer.h"

void Add(const Json::Value &req, Json::Value &rsp)
{
    int num1 = req["num1"].asInt();
    int num2 = req["num2"].asInt();
    rsp = num1 + num2;
}
int main()
{
    std::unique_ptr<rpc::ServiceDescribeFactory> desc_factory(new rpc::ServiceDescribeFactory());
    desc_factory->setMethod("Add");
    desc_factory->addParamDesc("num1", rpc::VType::INTEGRAL);
    desc_factory->addParamDesc("num2", rpc::VType::INTEGRAL);
    desc_factory->setResultType(rpc::VType::INTEGRAL);
    desc_factory->setCallback(Add);

    rpc::server::RpcServer server(rpc::Address("127.0.0.1", 9090));
    server.registerMethod(desc_factory->build());
    server.start();
    return 0;
}